package com.kabuda.zhugehot200;

import java.util.Arrays;

/**
 * @author kabuda
 * @date 2025-03-17 22:42
 * @description
 */
public class t976_三角形的最大周长 {
    public static void main(String[] args) {
        System.out.println(largestPerimeter(new int[]{2, 1, 3, 4}));
    }

    /**
     * @param nums
     * @return
     */
    public static int largestPerimeter(int[] nums) {
        Arrays.sort(nums);
        for (int i = nums.length - 1; i >= 2; i--) {
            if (nums[i] < nums[i - 1] + nums[i - 2]) {
                return nums[i] + nums[i - 1] + nums[i - 2];
            }
        }
        return 0;
    }
}
